//
//  ViewController.m
//  BlockTest
//
//  Created by 崔宝印 on 2017/12/7.
//  Copyright © 2017年 Koolearn. All rights reserved.
//

#import "ViewController.h"
#import "StrongSelfBlockController.h"
#import "BlockAsFuncParamController.h"

@interface ViewController ()
@property (nonatomic, strong) NSString *testName;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.testName = @"123";
//    
//    __weak __typeof(self) WeakSelf = self;
//    void(^strongBlock)(void) = ^(void){
//        __strong __typeof(WeakSelf) strongSelf = WeakSelf;
//        NSLog(@"VarA:%@",strongSelf.testName);
//    };
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        strongBlock();
//    });

    __block int i = 1;
    
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.0001 repeats:YES block:^(NSTimer * _Nonnull timer) {
//            //        self.testString = nil;
//            self.testString = [[NSMutableString alloc] initWithFormat:@"%d",i++];
//            self.testString = [self.testString mutableCopy];
//            //        self.testString = [[NSMutableString alloc] initWithFormat:@"%d",i++];
//            NSLog(@"!!!!!!%p",_testString);
//            NSLog(@"####%@",_testString);
//        }];
//        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
//        [[NSRunLoop currentRunLoop] run];
//    });


}

- (void)dealloc
{
    NSLog(@"%s",__func__);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//    BlockController *controller = segue.destinationViewController;
//    __weak __typeof(controller) weakController = controller;
//    controller.testBlock = ^{
//        __strong __typeof(controller) stongController = weakController;
//        while (1) {
////            NSLog(@"11111");
//            NSLog(@"%@",stongController.testName);
//        }
//    };
//    controller.testBlock();
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        __weak __typeof(controller) stongController = weakController;
//        stongController.testBlock();
//    });
    if ([segue.destinationViewController isKindOfClass:[BlockAsFuncParamController class]])
    {
        BlockAsFuncParamController *controller = segue.destinationViewController;
        
        ParamTestBlock block1 = ^(int m){NSLog(@"1:%d",1*m);};
        ParamTestBlock block2 = ^(int m){NSLog(@"2:%d",2*m);};

        [controller.array addObject:block1];
        [controller.array addObject:block2];
        [controller.array addObject:^(int m){NSLog(@"3:%d",3*m);}];
        [controller.array addObject:^(int m){NSLog(@"4:%d",4*m);}];
    }
    
    if ([segue.destinationViewController isKindOfClass:[StrongSelfBlockController class]])
    {
        StrongSelfBlockController *controller = segue.destinationViewController;
        [controller setTestWithController:self];
    }
}

@end
